//
//  TalkViewController.m
//  Bettle
//
//  Created by Apple on 2016/12/31.
//  Copyright © 2016年 panhongliu. All rights reserved.
//
#import "TalkTableViewCell.h"
#import "ActivityController.h"
#import "SDCycleScrollView.h"
#import "TalkViewController.h"
//#import "UIView+YZTCView.h"
@interface TalkViewController ()
@property(nonatomic,strong)SDCycleScrollView *cycleScrollView;
@property(nonatomic,strong)NSMutableArray *imagesURLStrings;
@end

@implementation TalkViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];
    _imagesURLStrings = [NSMutableArray array];
    [self reloData:YES];
    //下拉刷新上啦加载;
    [self customTableView];

    WeakSelf(refreshWeak, self);
    [self setTableHeaderRefresh:^{
        [refreshWeak reloData:YES];
    }];
    [self setFooterfresh:^{
        [refreshWeak reloData:NO];
    }];
    
    [self setTitle:@"社交"];
    [self registerNib:@"TalkTableViewCell"];
     self.tableview.frame=CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-64-49);
    ///UINib *footerNib= [UINib nibWithNibName:@"TalkTableViewCell" bundle:nil];
    ///[self.tableview registerNib:footerNib forCellReuseIdentifier:@"TalkTableViewCell"];
}

-(void)reloData:(BOOL)refresh{
    
    if (refresh) {
        self.currentIndex = 1;
    }else{
        self.currentIndex++;
    }
    [NetworkManger getCacheRequestWithUrlString:@"/beetle/inter/advert/getAdvertList" parameters:@{@"pageNumber":cunrrenIndex,@"displayNumber":@"5",@"page":@"0"} cacheTime:NO succeed:^(id data) {
        [self endReFresh];
        if (refresh) {
            [_imagesURLStrings removeAllObjects];
        }
        for (NSDictionary *dic in data[@"values"]) {
            [_imagesURLStrings addObject:dic[@"image"]];
        }
        NSLog(@"%@&@&&@&@&@&",_imagesURLStrings);
        [self.tableview reloadData];
        
    } fail:^(NSError *error) {
        
    }];
    
    
//    
//    [NetworkManger getCacheRequestWithUrlString:@"/beetle/inter/advert/getAdvertList?type=1&&pageNumber=1&displayNumber=5" parameters:@{@"pageNumber":cunrrenIndex,@"displayNumber":@"5"} cacheTime:NO succeed:^(id data) {
//        for (NSDictionary *dic in data[@"values"]) {
//            [self.dataArray addObject:dic];
//        }
//        [self.tableview reloadData];
//        
//    } fail:^(NSError *error) {
//        
//    }];
//
//
}



- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 244;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 285;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    _cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, ScreenWidth, 200) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _cycleScrollView.imageURLStringsGroup = _imagesURLStrings;
    UIImage *iamge1 = [UIImage imageNamed:@"carouse_spot_routine"];
    UIImage *iamge2 = [UIImage imageNamed:@"carouse_spot_selected"];
    _cycleScrollView.currentPageDotImage = iamge2;
    _cycleScrollView.pageDotImage = iamge1;
    
    _cycleScrollView.pageControlDotSize =CGSizeMake(8, 8);
    _cycleScrollView.scrollDirection = UICollectionViewScrollDirectionVertical;
    _cycleScrollView.backgroundColor = [UIColor blackColor];
    _cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
    _cycleScrollView.scrollDirection =UICollectionViewScrollDirectionHorizontal
    ;
    //--- 轮播时间间隔，默认1.0秒，
    _cycleScrollView.autoScrollTimeInterval = 3;
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 244)];
    view1.backgroundColor = [UIColor whiteColor];
    [view1 addSubview:_cycleScrollView];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 200, SCREEN_WIDTH, 43)];
    [view1 addSubview:view];
    UIView *viewbuttom = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 1)];
    view.backgroundColor = UIColorFromRGB(0xe8e8e8);
    [view addSubview:viewbuttom];
    
     NSArray *array1= [[NSArray alloc]initWithObjects:@"活动",@"寻觅",@"部落", nil];
    for (int i = 0; i<3; i++) {
        
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake((ScreenWidth-3)/3*i+1*i, _cycleScrollView.bottom, (ScreenWidth-3)/3, 42)];
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(btn.right,btn.top+6, 1, btn.height-12)];
        lineView.backgroundColor = UIColorFromRGB(0xe8e8e8);
        [btn setTitle:array1[i] forState:UIControlStateNormal];
        [btn setTitleColor:UIColorFromRGB(0x14141)forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor whiteColor];
        btn.userInteractionEnabled = YES;
        btn.tag = 100+i;
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        [view1 addSubview:btn];
        [view1 addSubview:lineView];
    }
    ;
    
    return view1;
    
}
-(void)btnAction:(UIButton *)sender{
    ActivityController *AC = [[ActivityController alloc]init];
    [self pushNextViewController:AC];
    
}
    

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //    if (indexPath.row ==1) {
    //        MainTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MainTableViewCell1" forIndexPath:indexPath];
    //        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    //
    //        return cell;
    //
    //    }else{
    TalkTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TalkTableViewCell" forIndexPath:indexPath];
    [cell cellFuzhi];
    
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    return cell;
    
    //}
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSLog(@"基类里输出请重写方法");
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    if (self.didSelectCellBlock) {
        self.didSelectCellBlock(indexPath) ;
        
    }
}



@end
